{-# OPTIONS_GHC -fth -fglasgow-exts #-}
--                -fallow-undecidable-instances
--                -fallow-overlapping-instances
--                -fallow-incoherent-instances
{-
    Proof of Concept Relational System

    relations  are represented as lists of tuples.
    attributes are represented as types.
    relational dimensions limit: 4
    joins support relations where results are up to the dimensional limit.
-}
module Relational (
        Isomorphism,
        Projection,
        isomorphisms
    ) where
import Data.Tuple.Projection
import Relational.Internal
import Data.Generics
import Data.Maybe

class Isomorphism a b where
    isomorph :: a -> b

{-
    class Selection is removed. use filter instead.
-}

instance Isomorphism a a where isomorph = id

instance (Isomorphism a b) => Isomorphism [a] [b] where isomorph = map isomorph


instance Projection (a,(b,c)) (a,b,c) where project (a,(b,c)) = (a,b,c)
instance Projection ((a,b),c) (a,b,c) where project ((a,b),c) = (a,b,c)
instance Projection ((a,b),c,d) (a,b,c,d) where project ((a,b),c,d) = (a,b,c,d)
instance Projection (a,(b,c),d) (a,b,c,d) where project (a,(b,c),d) = (a,b,c,d)
instance Projection (a,b,(c,d)) (a,b,c,d) where project (a,b,(c,d)) = (a,b,c,d)
instance Projection ((a,b),(c,d)) (a,b,c,d) where project ((a,b),(c,d)) = (a,b,c,d)
instance Projection ((a,b,c),d) (a,b,c,d) where project ((a,b,c),d) = (a,b,c,d)
instance Projection (a,(b,c,d)) (a,b,c,d) where project (a,(b,c,d)) = (a,b,c,d)
instance Projection (((a,b),c),d) (a,b,c,d) where project (((a,b),c),d) = (a,b,c,d)
instance Projection ((a,(b,c)),d) (a,b,c,d) where project ((a,(b,c)),d) = (a,b,c,d)
instance Projection (a,((b,c),d)) (a,b,c,d) where project (a,((b,c),d)) = (a,b,c,d)
instance Projection (a,(b,(c,d))) (a,b,c,d) where project (a,(b,(c,d))) = (a,b,c,d)



class Join1st r1 r2 r3 | r1 r2 -> r3 where
    join1st :: r1 -> r2 -> r3


$(expandIsomorphismsUpToDim 12)
-- $(joinsUpToDimN       4)

